package cn.his.medical.phismange.adapter

import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.ImageView
import android.widget.TextView
import cn.his.medical.phismange.R
import cn.his.medical.phismange.bean.ViewPagerBean

/**
 * @类名 ViewPagerAdapter
 * @描述  适配器
 * @作者 xiewei
 * @创建时间 2018/4/3 14:18
 */
class MyAdapter(val list: ArrayList<ViewPagerBean>?, val context: Context) : BaseAdapter() {
    override fun getView(p0: Int, p1: View?, p2: ViewGroup?): View {
        var holder: TestViewHolder
        var v: View
        if (p1 == null) {
            v = View.inflate(context, R.layout.view_pager_item, null)
            holder = TestViewHolder(v)
            v.tag = holder
        } else {
            v = p1
            holder = v.tag as TestViewHolder
        }
        var viewPagerBean = list?.get(p0) as ViewPagerBean
        holder.t_sub_head.text = viewPagerBean.t_sub_head
        holder.t_user_name.text = viewPagerBean.t_user_name
        holder.t_intro.text = viewPagerBean.t_intro
        holder.t_show_time.text = viewPagerBean.t_show_time
        holder.t_show_address.text = viewPagerBean.t_show_address
        holder.t_show_phone.text = viewPagerBean.t_show_phone
        return v

    }

    override fun getItem(p0: Int): Any {
        if (list != null) {
            return list.get(p0)
        } else {
            return ""
        }
    }

    override fun getItemId(p0: Int): Long {
        return p0.toLong()
    }

    override fun getCount(): Int {
        if (list != null) {
            return list.size
        } else {
            return 0;
        }
    }
}

class TestViewHolder(var viewItem: View) {
    var img_user = viewItem.findViewById(R.id.img_user) as ImageView
    var t_sub_head = viewItem.findViewById(R.id.t_sub_head) as TextView
    var t_user_name = viewItem.findViewById(R.id.t_user_name) as TextView
    var t_intro = viewItem.findViewById(R.id.t_intro) as TextView
    var t_show_time = viewItem.findViewById(R.id.t_show_time) as TextView
    var t_show_address = viewItem.findViewById(R.id.t_show_address) as TextView
    var t_show_phone = viewItem.findViewById(R.id.t_show_phone) as TextView
}